home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.hitl.washington.edu
/
ftp.hitl.washington.edu.tar
/
ftp.hitl.washington.edu
/
pub
/
people
/
tsoper
/
CT Explorer
/
3DElementIndexer.cs
next >
Wrap
Text File
|
2005-06-07
|
4KB
|
206 lines
//3DElementIndexer.cs
//This class was written to ease conversion between scan coordinates
//in row-column-plane (RCP) to right-handed cartesian coordinates
//in x-y-z (XYZ). With this class, respective correspondence between
//matrix dimensions, and 3D axes is set up once precluding a lot of
//confusing code. The indexer only stores the RCP index subscripts in
//the 3 element vector rcpIndex. The xyzCorr vector containes possible
//values of 0,1, or 2. The ith element of xyzCorr correlates with the
//ith axis in XYZ where X=0, Y=1, Z=2. The value stored there
//corresponds to the dimension of the matrix in RCP where row = 0,
//column = 1, plane = 2. The isNegative vector specifices if any
//indexes need to be negated before converting RCP to XYZ. No XYZ data
//is stored; all accessors convert from RCP when the data is retrieved.
//THIS CLASS IS NOT LINKED TO DATA, IT IS JUST AN INDEX.
//THINGS TO DO: 1) switch out vectors for class with xyz or rcp properties
// 2) change method inputs to (AXIS) enumeration rather than int
using System;
public enum AXIS_ALIGN
{
POSITIVE_X,
POSITIVE_Y,
POSITIVE_Z,
NEGATIVE_X,
NEGATIVE_Y,
NEGATIVE_Z,
}
public class ElementIndexer3D
{
//Attributes
private int[] rcpIndex = new int[3]; //actual index is stored in
//RCP format
private int[] xyzCorr = new int[3]; //correspondence of
//xyz to rcp
private bool[] isNegative = new bool[3]; //negative axis corresp.
float[] scaleFactor = new float[3]; //scaling of rcp to xyz
//Properties
public int X //get/set the X element
{
get
{
return GetXYZElement(0);
}
set
{
SetXYZElement(0,value);
}
}
public int Y //get/set the Y element
{
get
{
return GetXYZElement(1);
}
set
{
SetXYZElement(1,value);
}
}
public int Z //get/set the Z element
{
get
{
return GetXYZElement(2);
}
set
{
SetXYZElement(2,value);
}
}
public int Row //get/set the Row element
{
get
{
return rcpIndex[0];
}
set
{
rcpIndex[0] = value;
}
}
public int Column //get/set the Column element
{
get
{
return rcpIndex[1];
}
set
{
rcpIndex[1] = value;
}
}
public int Plane //get/set the Plane element
{
get
{
return rcpIndex[2];
}
set
{
rcpIndex[2] = value;
}
}
public int[] RCPIndex //get/set the full RCP index vector
{
get
{
return (int[])rcpIndex.Clone();
}
set
{
rcpIndex[0] = value[0];
rcpIndex[1] = value[1];
rcpIndex[2] = value[2];
}
}
public int[] XYZIndex //get/set the full XYZ index vector
{
get
{
int[] xyzIndex = {X,Y,Z};
return xyzIndex;
}
set
{
X = value[0];
Y = value[1];
Z = value[2];
}
}
//overloaded constructors:
public ElementIndexer3D(AXIS_ALIGN xCorr,AXIS_ALIGN yCorr,
AXIS_ALIGN zCorr)
{
AXIS_ALIGN[] corr = {xCorr,yCorr,zCorr};
MakeAssignments(corr);
}
public ElementIndexer3D(AXIS_ALIGN[] corr)
{
MakeAssignments(corr);
}
//Assign correspondences in the xyzCorr variable
private void MakeAssignments(AXIS_ALIGN[] corr)
{
for(int i =0; i < 3; i++)
{
int axisCorr = (int)corr[i]; //convert enum to int
//adjust if it is negative
if (axisCorr >= 3)
{
isNegative[i] = true;
axisCorr -= 3;
}
else
isNegative[i] = false;
xyzCorr[i] = axisCorr; //set the correspndence
}
}
//set
public int GetXYZElement(int axis)
{
if(isNegative[axis])
return -rcpIndex[xyzCorr[axis]];
else
return rcpIndex[xyzCorr[axis]];
}
public void SetXYZElement(int axis, int index)
{
rcpIndex[xyzCorr[axis]] = Math.Abs(index);
//force subscripts to be +
}
private void SetRCPElement(int dimension, int index)
{
rcpIndex[dimension] = index;
}
}